package com.ddwl.data.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.data.ImageBo;
import com.ddwl.schema.bo.data.ImagePageBo;
import com.ddwl.schema.vo.data.ImageVo;
import com.ddwl.data.service.ImageLibService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author hemiaojun
 * @Date 2021/7/5 11:49
 */

@Api(tags = "图片库")
@RequestMapping("/imageLib")
@RestController
@RequiredArgsConstructor
public class ImageLibController extends BaseController {

    private final ImageLibService imageLibService;



    @PostMapping()
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE, BaseEnum.ProductEnum.SHOP_CONSOLE, BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("保存图片")
    public RestVo<String> uploadImg(@Valid @RequestBody ImageBo bo){
        bo.setUserId(getUserId());
        if (BaseEnum.ProductEnum.SHOP_CONSOLE.getName().equals(getProduct()) && !StringUtils.hasText(bo.getShopId())) {
            bo.setShopId(getShopId());
        }
        return RestVo.ok(imageLibService.uploadImg(bo));
    }

    @PostMapping("/page")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE, BaseEnum.ProductEnum.SHOP_CONSOLE, BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("分页查询")
    public RestVo<PageVo<ImageVo>> page(@Valid @RequestBody PageBo<ImagePageBo> bo){
        return RestVo.ok(imageLibService.page(bo));
    }



}
